using System;
using System.Linq;
using Furion;
using SqlSugar;

namespace Admin.NET.Application.SqlSugarTD;

public class SqlSugarTDClient
{
	private static SqlSugarClient _client;

	public static SqlSugarClient GetClient()
	{
		if (_client == null)
		{
			SqlSugarTDConfig conn = App.GetOptions<SqlSugarTDConfig>();
			_client = new SqlSugarClient(new ConnectionConfig
			{
				DbType = DbType.TDengine,
				ConnectionString = conn.ConnectionString,
				IsAutoCloseConnection = true,
				AopEvents = new AopEvents
				{
					OnLogExecuting = delegate(string sql, SugarParameter[] p)
					{
						Console.WriteLine(sql);
						Console.WriteLine(string.Join(",", p?.Select((SugarParameter it) => it.ParameterName + ":" + it.Value)));
					}
				}
			});
		}
		return _client;
	}
}
